package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Employee;
import com.zretc.entity.EmployeeSalary;
import com.zretc.entity.ResponseResult;
import com.zretc.entity.Salary;
import com.zretc.service.EmployeeSalaryService;
import com.zretc.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/employeesalary")
public class EmployeeSalaryContorller {

    @Autowired
    private EmployeeSalaryService employeeSalaryService;
    @Autowired
    private SalaryService salaryService;

    @RequestMapping("/get")
    public ResponseResult getByPage(Integer page, Integer size, String name){

        Map<String,Object> map=new HashMap<>();
        map.put("page",page);
        map.put("size",size);
        map.put("name",name);
        PageInfo<EmployeeSalary> pageInfo = employeeSalaryService.find(map);
        return ResponseResult.ok("查询成功",pageInfo);
    }

    @PutMapping("/update")
    public ResponseResult update(Integer employeeId, Integer salaryId){

        int update = employeeSalaryService.updata(employeeId,salaryId);
        if (update>0){
            return ResponseResult.ok("修改成功");
        }
        return ResponseResult.ok("修改失败");
    }
    @RequestMapping("/get1")
    public ResponseResult getSalary(){

        Map<String,Object> map=new HashMap<>();
        List<Salary> all = salaryService.findAll(map);
        return ResponseResult.ok("查询成功",all);
    }



}
